<template>
    <div>
        <h1>这是A组件</h1>
        {{ name }} --- {{ age }} --- {{ changeAge }}
        <button @click="changeName">修改名字</button>

        <button @click="updateAgeInA">修改年龄</button>
    </div>
</template>

<script setup lang="ts">
import { storeToRefs } from 'pinia';
import { userStore } from '../store/user';
const store = userStore();
let { name, age, changeAge } = storeToRefs(store); // store

const changeName = () => {
    // name.value = '阿尔维奇';
    // age.value = 20;
    // 批量修改
    store.$patch(state => {
        state.age++;
        state.name = '阿尔维奇';
    })
}

const updateAgeInA = () => {
    store.updateAge(18);
}
</script>